package com.csi.sai.utilities.templates.selects;

import java.sql.ResultSet;
import java.sql.SQLException;

public class ComboCorreo implements ComponentTemplate {
	
	private String htmlCode;
	
	@Override
	public void setRS(ResultSet rs) throws SQLException {
		StringBuffer sb = new StringBuffer();
		sb.append("<span class=\"lblSpan\">Correo</span>");
		sb.append("<select id=\"ccMail_1\" class=\"combobox\">");
		while(rs.next()) {
			sb.append("<option {selected} id=\""+rs.getInt(1)+"\">"+rs.getString(2)+"</option>");
		}
		sb.append("</select>");
		
		this.htmlCode = sb.toString();
	}
	
	@Override
	public void setRS(ResultSet rs, int idSelected) throws SQLException {
		StringBuffer sb = new StringBuffer();
		//sb.append("<span class=\"lblSpan\">Correo</span>");
		//sb.append("<select id=\"ccMail_1\" class=\"combobox\">");
		while(rs.next()) {
			if(idSelected==rs.getInt(1)) {
				sb.append("<option selected=\"selected\" id=\""+rs.getInt(1)+"\">"+rs.getString(2)+"</option>");
			} else {
				sb.append("<option id=\""+rs.getInt(1)+"\">"+rs.getString(2)+"</option>");
			}
		}
		//sb.append("</select>");
		
		this.htmlCode = sb.toString();
	}
	
	@Override
	public String getComponentGeneric() {
		// TODO Auto-generated method stub
		return this.htmlCode;
	}
	

}
